﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.ManagerCategory
{
    public partial class CategoryAdd : System.Web.UI.Page
    {

        CategoryBLL caBll = new CategoryBLL();       
        public IList<Category> catePrList = new List<Category>();

        ProdTypeBLL prodTypeBll = new ProdTypeBLL();
        public IList<ProdType> typeList = new List<ProdType>();

        protected void Page_Load(object sender, EventArgs e)
        {
            catePrList = caBll.FindListPro();
            typeList = prodTypeBll.FindAll();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int GoodsType = 0;
            int parentId = int.Parse(Request["ParentId"]);
            string caName =StringUtil.checkStr(this.CatName.Text);
            int SortOrder = int.Parse(Request["SortOrder"]);
            string MeasureUnit =StringUtil.checkStr(this.MeasureUnit.Text);
            string IsShow = Request["IsShow"];
            string CatDesc = Request["CatDesc"];
            string KeyWord = StringUtil.checkStr(this.KeyWord.Text);
            caName = caName.Trim().Replace(" ", "");
            if (!string.IsNullOrEmpty(Request["GoodsType"]))
            {
                GoodsType = int.Parse(Request["GoodsType"]);
            }
            caBll.entity = caBll.FindModelByName(parentId, caName);
            if (caBll.entity != null)
            {
                StringUtil.Alert("此类别已存在！", "-1");
            }
            else
            {
                Category ca = new Category();
                ca.ParentId = parentId;
                ca.CatName = caName;
                ca.KeyWord = KeyWord;
                ca.MeasureUnit = MeasureUnit;
                ca.SortOrder = SortOrder;
                ca.IsShow =IsShow=="true"?true:false;
                ca.CatDesc = CatDesc;
                ca.GoodsType = GoodsType;
                caBll.entity = ca;
                if (caBll.Add())
                {
                    StringUtil.Alert("添加成功！","CategoryList.aspx");
                }
                else
                {
                    StringUtil.Alert("添加失败！", "-1");

                }
            }
        }

    }
}
